var domain = "pangsuan.com";//这里改为你网站的域名，注意格式！！！
const app = getApp();
Page({
      data:{
            sceneCode:'',
            scanBtn:true
      },
      onLoad(query) {
            var that = this;
            const scene = decodeURIComponent(query.scene)
            if(scene == 'undefined'){
                  that.setData({
                        sceneCode:'',
                        status:'请使用微信扫一扫',
                        scanBtn:true
                  })
            }else{
                  that.setData({
                        sceneCode:scene,
                        status:'请点击授权登录',
                        scanBtn:false
                  })
            }
            wx.request({
                  url: 'https://' + domain + '/tepass/mp_loginscancode?scene='+that.data.sceneCode,
                  data: {},
                  header: {
                        'content-type': 'application/json'
                  },
                  success (res) {
                        console.log(that.data.sceneCode)
                  }
            })
      },

      // 点击授权登录
      loginRequest:function(){
            var that = this;
            that.setData({
                  loadingstatus:true
            })
            wx.login({
                  success (res) {
                        if (res.code) {
                              wx.request({
                                    url: 'https://' + domain + '/tepass/mp_loginrequest',
                                    data: {
                                          code: res.code,
                                          scene: that.data.sceneCode
                                    },
                                    success (res) {
                                          console.log(res.data)
                                          if(res.data.code == 200){
                                                wx.showToast({
                                                      title: '登录成功',
                                                      icon: 'none',
                                                      duration: 2000
                                                })
                                                that.setData({
                                                      status:'已登录',
                                                      scanBtn:true
                                                })
                                          }else{
                                                wx.showToast({
                                                      title: '登录失败',
                                                      icon: 'none',
                                                      duration: 2000
                                                })
                                          }
                                    }
                              })
                        }
                  }
            })
      }
})